package com.copa.l1232;

/**
 * @author copa
 * @createDate 2022-08-30 11:14
 * @function
 */
public class Test1 {

    public boolean checkStraightLine(int[][] coordinates) {
        if (coordinates.length == 2) {
            return true;
        }
        // 这个相当于是一元一次方程 y=kx+b 但是不建议求k...而是转化为求两点的k是否相等
        // 因为求k有个麻烦 肯定要除法 计算机对除法的效率低，宁愿乘法也不要除法
        // (y-y1)/(x-x1)=(y-y2)/(x-x2) ----> (y-y1)(x-x2)=(y-y2)(x-x1) 咱们取第一个点和最后一个点
        int x1 = coordinates[0][0];
        int y1 = coordinates[0][1];
        int x2 = coordinates[coordinates.length - 1][0];
        int y2 = coordinates[coordinates.length - 1][1];
        for (int i = 1; i < coordinates.length - 1; i++) {
            if ((coordinates[i][1] - y1) * (coordinates[i][0] - x2)
                    != (coordinates[i][1] - y2) * (coordinates[i][0] - x1)) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        //int[][] coordinates = {{2,1},{4,2},{6,3}};
        //int[][] coordinates = {{0,0},{0,1},{0,-1}};
        int[][] coordinates = {{1,2},{2,3},{3,4},{4,5},{5,6},{6,7}};
        System.out.println(new Test1().checkStraightLine(coordinates));
    }
}
